﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Calc
{
    public partial class Form1 : Form
    {
        float Chislo1, Chislo2;
        float i;
        string znak;
        

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            znak = label2.Text;
            if ((textBox1.Text == "") || (textBox2.Text == ""))
                MessageBox.Show("поле пустое");
            else
            {
                if (Checking_the_lines())
                {

                    Chislo1 = float.Parse(textBox1.Text);
                    Chislo2 = float.Parse(textBox2.Text);

                    if (znak == "+")
                        label1.Text = ((float)(Chislo1 + Chislo2)).ToString();
                    if (znak == "-")
                        label1.Text = ((float)(Chislo1 - Chislo2)).ToString();
                    if (znak == "/")
                    {
                        i = (float)(Chislo1 / Chislo2);
                        label1.Text = (i).ToString();
                    }
                    if (znak == "*")
                        label1.Text = ((float)(Chislo1 * Chislo2)).ToString();
                }
                else MessageBox.Show("Введите цифры");
            }
        }

        public bool Checking_the_lines()
        {
            string Str = textBox1.Text.Trim();
            float Num;
            bool isNum = float.TryParse(Str, out Num);
            if (isNum)
                return true;
            else
                return false;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            label2.Text = "+";
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label2.Text = "-";
        }

        private void button4_Click(object sender, EventArgs e)
        {
            label2.Text = "/";
        }

        private void button5_Click(object sender, EventArgs e)
        {
            label2.Text = "*";
        }
    }
}
